package com.wf.ew.orderB.service.impl;

import com.wf.ew.common.JsonResult;
import com.wf.ew.common.PageResult;
import com.wf.ew.system.model.User;
import com.wf.ew.orderB.biz.BillBiz;
import com.wf.ew.orderB.model.Bill;
import com.wf.ew.orderB.service.BillService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.List;

/**
 *
 * 数据服务层接口实现类
 * @author : Doman
 * @date : 2020-04-13 13:50:45
 * @version ：1.0
 */
@Service
public class BillServiceImpl implements BillService {

	@Autowired
	private BillBiz billBiz;

	@Override
	public String allApiList(PageResult<T> page, Bill bill, User loginUser) {
		return billBiz.allApiList(page,bill,loginUser);
	}
	@Override
	public List<Bill> allApiList(Bill bill) {
		return billBiz.allApiList(bill);
	}

	@Override
	public String list(PageResult<T> page, Bill bill, User loginUser) {
		return billBiz.list(page,bill,loginUser);
	}

	@Override
	public List<Bill> list(Bill bill, User loginUser) {
		return billBiz.list(bill,loginUser);
	}

	@Override
	public int selectCountOrderDay(Bill bill, User loginUser) {
		return billBiz.selectCountOrderDay(bill);
	}

	@Override
	public List<Bill> selectWkOrderFirst(Bill bill) {
		Integer count = billBiz.selectCountOfScore(bill);
		Integer count1 = billBiz.selectCountOrderDay(bill);
		if (count == count1 && count != 0 && count1 != 0) {
			bill.setKeywords("");
			return billBiz.selectWkOrderFirst(bill);
		} else {
			bill.setKeywords("1");
			return billBiz.selectWkOrderFirst(bill);
		}
	}
	@Override
	public List<Bill> selectShareOrders(Bill bill) {
		return billBiz.selectShareOrders(bill);
	}
	@Override
	public List<Bill> selectOrderCus(Bill bill) {
		return billBiz.allApiListByNow(bill);
	}

	@Override
	public Bill getById(Bill bill) {
		return billBiz.getById(bill);
	}

	@Transactional
	@Override
	public JsonResult add(Bill bill, User loginUser) {
		if (billBiz.add(bill, loginUser)) {
			return JsonResult.ok("添加成功");
		}
		return JsonResult.error("添加失败");
	}


	@Transactional
	@Override
	public JsonResult update(Bill bill, User loginUser) {
		if (billBiz.update(bill, loginUser)) {
			return JsonResult.ok("修改成功");
		}
		return JsonResult.error("修改失败");
	}

	@Transactional
	@Override
	public JsonResult update2(Bill bill, User loginUser) {
		if (billBiz.update2(bill, loginUser)) {
			return JsonResult.ok("修改成功");
		}
		return JsonResult.error("修改失败");
	}

	@Transactional
	@Override
	public JsonResult delete(Bill bill, User loginUser) {
		if (billBiz.delete(bill, loginUser)) {
			return JsonResult.ok("删除成功");
		}
		return JsonResult.error("删除失败");
	}
}
